﻿using QuanLyGiaoVuService.ReportServices;
using QuanLyGiaoVuService.CommonServices;
using QuanLyGiaoVuUI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QuanLyGiaoVuUI.Models.Mappers;
using QuanLyGiaoVuUI.Models.GiangVienClient;
using QuanLyGiaoVuUI.Models.GiangVien;
using QuanLyGiaoVuUI.Models.LopMonHoc;
using QuanLyGiaoVuUI.Models.Common;
using QuanLyGiaoVuService.CommandServices;
using QuanLyGiaoVuDAL.DTO;
using QuanLyGiaoVuUI.Models.NguoiDung;

namespace QuanLyGiaoVuUI.Controllers
{
    public class CommonController : Controller
    {
        //
        // GET: /Common/
        private IGiangVienReportService _giangVienReportService;
        private IGiangVienCommandService _giangVienCommandService;
        private ILopMonHocCommandService _lopMonHocCommandService;
        private ILopMonHocReportService _lopMonHocReportService;
        private IThamSoService _thamSoService;
        private IHocKyReportService _hocKyReportService;
        private IDangKyGioDayCommandService _dangKyGioDayCommandService;
        private IDangKyGioDayReportService _dangKyGioDayReportService;
        private INguoiDungCommandService _nguoiDungCommandService;
        private INguoiDungReportService _nguoiDungReportService;
        private ITietHocService _tietHocService;
        private IDeTaiCommandService _deTaiCommandService;
        private IDeTaiReportService _deTaiReportService;
        private IDangKyKetThucLopMonHocCommandService _dangKyKetThucLopMonHocCommandService;
        private IDangKyKetThucLopMonHocReportService _dangKyKetThucLopMonHocReportService;

        public CommonController(IGiangVienCommandService giangVienCommandService,
            IGiangVienReportService giangVienReportService,
            IThamSoService thamSoservice,
            ILopMonHocReportService lopMonHocReportService,
            ILopMonHocCommandService lopMonHocCommandService,
            IHocKyReportService hocKyReportService,
            IDangKyGioDayReportService dangKyGioDayReportService,
            IDangKyGioDayCommandService dangKyGioDayCommandService,
            INguoiDungCommandService nguoiDungCommandService,
            INguoiDungReportService nguoiDungReportService,
            IDeTaiCommandService deTaiCommandService,
            IDeTaiReportService deTaiReportService,
            ITietHocService tietHocService,
            IDangKyKetThucLopMonHocCommandService dangKyKetThucLopMonHocCommandService,
            IDangKyKetThucLopMonHocReportService dangKyKetThucLopMonHocReportService)
        {
            commonViewModel = new CommonViewModel();

            _giangVienReportService = giangVienReportService;
            _giangVienCommandService = giangVienCommandService;
            _thamSoService = thamSoservice;
            _lopMonHocReportService = lopMonHocReportService;
            _lopMonHocCommandService = lopMonHocCommandService;
            _hocKyReportService = hocKyReportService;
            _dangKyGioDayCommandService = dangKyGioDayCommandService;
            _dangKyGioDayReportService = dangKyGioDayReportService;
            _nguoiDungCommandService = nguoiDungCommandService;
            _nguoiDungReportService = nguoiDungReportService;
            _deTaiCommandService = deTaiCommandService;
            _deTaiReportService = deTaiReportService;
            _tietHocService = tietHocService;
            _dangKyKetThucLopMonHocCommandService = dangKyKetThucLopMonHocCommandService;
            _dangKyKetThucLopMonHocReportService = dangKyKetThucLopMonHocReportService;

            StartAllCommonFunction();
        }
        public static CommonViewModel commonViewModel;
        public ActionResult Index()
        {
            return View();
        }
        private void StartAllCommonFunction()
        {
            String mahkHienTai = _thamSoService.GetThamSo("HocKyHienTai");
            HocKyDTO hocKy = _hocKyReportService.GetHocKyById(Guid.Parse(mahkHienTai));
            commonViewModel.HocKyHienTai = hocKy;

            commonViewModel.HocKyHienTaiNamHoc = _hocKyReportService.GetNamHocById(hocKy.MaNamHoc);
        }
        public ActionResult NamHocHienTai()
        {
            return View(commonViewModel);
        }
        public ActionResult HocKyHienTai()
        {
            return View(commonViewModel);
        }
        public ActionResult LichHoc()
        {
            IEnumerable<LopMonHocViewModel> lopMonHocViewModel = LopMonHocViewModel.FromLopMonHocDTOList(_lopMonHocReportService.GetAllLopMonHocTheoHocKy(new Guid(_thamSoService.GetThamSo("HocKyHienTai")), null, null, true)).OrderBy(lop => lop.MaMonHoc);
            return View(lopMonHocViewModel);
        }

    }
}
